
let pi = acos (-1.)

class simple_modulator a f p =
object
  val amplitude = a
  val ffreq 	= f *. 2. *. pi
  val phase 	= p
  method signal t = 
	amplitude *. sin (phase +. ffreq *. t)
end


class basic_envelope a ma s ms r =
object 
  method amplitude t = 
	if t <= 0. then
		0.
	else if t <= a then
		t *.  ma /. a 
	else if t > a && t <= s then
		(t -. a) *. (ms -. ma) /. (s -. a) +. ma
	else if t > s && t <= r then
		(t -. s) *. (-.ms) /. (r -. s) +. ms
	else 
		0.
end

class env_modulator env f p =
object
  inherit simple_modulator 1. f p as sim_mod
  val form = env
  method signal t = 
	(form#amplitude t) *. (sim_mod#signal t)
end

